#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

int testDiscardCard(struct gameState *state) {
	int i, j, k;
	int player, handPos, card;
	
	for (player = 0; player < state->numPlayers; player ++) {
		handPos = 0; 
		i = 0;
		j = state->handCount[player];
		k = 0;
		printf("\tTesting for player %d:  \t", player);
		int p;
		for (p=0;p<10;p++) {
			gainCard(p,state,2,player);
		}
		handPos = 0; 
		i = 0;
		j = state->handCount[player];
		printf("%d cards in hand, ", j);
		k = 0;
		while (k < j) {
			card = state->hand[player][j-k-1];
			discardCard(handPos, player, state, 1);
			k += 1;
			if(state->handCount[player] > 0) {
				assert(card == state->hand[player][handPos]);
			}
			assert(-1 == state->hand[player][j-k]);
			assert((k+state->handCount[player]) == j);
		}
		printf("%d discards passed\n", k);
	}
	return 0;
}

int main() {
    
    int seed = 1000;
    int numPlayer = 3;
    
	struct gameState G;
	struct gameState *state = &G;
	int k[10] = {adventurer, gardens, embargo, village, minion, mine, cutpurse, 
		   sea_hag, tribute, smithy};

	initializeGame(numPlayer, k, seed, &G);
	printf("Testing discardCard:\n");
	testDiscardCard(state);
	
	printf("  DiscardCard Passed all tests!\n");
	

    return 0;
}

